package com.example.newproject_overseas.Screen


import android.annotation.SuppressLint
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.DateRange
import androidx.compose.material.icons.filled.Home
import androidx.compose.material.icons.filled.Person
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.NavigationBarItemDefaults
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController
import com.example.newproject_overseas.Screen.Main.Home
import com.example.newproject_overseas.Screen.Main.My
import com.example.newproject_overseas.Screen.Main.OrderDetails
import com.example.newproject_overseas.model.entity.BottomItemData

@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun MainFrame(navController: NavHostController) {

    val selectedColor = Color(0xFFFFBE01) // 选中项的颜色
    val unselectedColor = Color(0xFF999999) // 未选中项的颜色

    var currentSelect by remember {
        mutableStateOf(0)
    }

    val menuData = listOf(
        BottomItemData("Home", Icons.Filled.Home),
        BottomItemData("Order Details", Icons.Filled.DateRange),
        BottomItemData("My", Icons.Filled.Person)
    )

    val customColors = NavigationBarItemDefaults.colors(

        indicatorColor      = Color(0xFFFFFFFF)

    )

    Scaffold(
        modifier = Modifier.fillMaxSize()
        , bottomBar = {
            NavigationBar(
                containerColor=Color(0xFFFFFFFF),
                modifier = Modifier
                    .navigationBarsPadding()
                    .fillMaxWidth()
                    ) {
                menuData.forEachIndexed { index, bottomItemData ->
                    val isSelected = index == currentSelect
                    NavigationBarItem(
                        selected = index == currentSelect,
                        colors =  customColors,
                        onClick = {
                            currentSelect = index
                        },
                        icon = {
                            Icon(
                                imageVector = bottomItemData.icon,
                                contentDescription = "点击按钮",
                                tint = if (isSelected) selectedColor else unselectedColor
                            )
                        },
                        label = {
                            Text(
                                text = (bottomItemData.title),
                                color = if (isSelected) selectedColor else unselectedColor
                            )
                        },
                    )
                }
            }
        }
    ) {
        Box(modifier = Modifier
            .fillMaxSize()
            .padding(it)
            .background(Color(0xFFF1F1F1))
        ){
            //下面第3步就是对此部分代码进行更改
            //下面第3步就是对此部分代码进行更改
            when(currentSelect){
                0 -> Home(navController)
                1 -> OrderDetails(navController)
                2 -> My()
            }

        }
    }


}

@Preview
@Composable
fun MainFramePreview() {
    val navController = rememberNavController() // 假设这里使用了导航控制器
    MainFrame(navController)
}

